import fly from "./main"

export function getOpenId($params) {
  return fly.get('https://api.weixin.qq.com/sns/jscode2session?appid=wxf9a040f8c7faaa66&secret=eb049dca1fd9db8617e07c5e56ce5956&js_code='+$params+'&grant_type=authorization_code ')
}

export function getPrepayId($params) {
  let $data = {
    "openid": $params
  }
  return fly.post('/v3/payment',$data)
}
export  function getPayData($params) {
  let $data = "prepay_id="+$params['prepay_id']
  return fly.get('/v3/payment/create', $data)
}




//注册保存openid
export function saveOpenId($params) {
  let $data = {
    "openid": $params
  }
  return fly.post('v3/login', $data)
}

//登录
export function doLogin($params) {
  let $data = {
    "openid": $params
  }
  return fly.get('v3/login/create', $data)
}


/**
 * 获取用户信息
 * @returns {Promise<{}>}
 */
export async function getUserInfo() {
  let response = {}
  await fly.get(`/v3/user/1`).then((res) => {
    response = res.data
  })
  return response;
}


/**
 * 获取系统配置信息
 * @returns {Promise<{}>}
 */
export async function getSystemConfig() {
  let response = {}
  await fly.get(`/v3/config`).then((res) => {
    response = res.data
  })
  return response;
}


/**
 * 获取用户信息
 * @returns {Promise<{}>}
 */
export async function updateUserInfo($params) {
  let response = {}
  await fly.put(`/v3/user/1`,$params).then((res) => {
    response = res.data
  })
  return response;
}
